package de.metalcon.gwt.client.interactions;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

public class LoginForm extends AStaticInteraction {

	Label nameLabel = new Label("Name:");
	TextBox nameBox = new TextBox();
	Label addrLabel = new Label("Address:");
	TextBox addrBox = new TextBox();
	Label phoneLabel = new Label("Phone number:");
	TextBox phoneBox = new TextBox();
	Button button = new Button("Submit");

	Grid grid = new Grid(4, 2);

	public LoginForm() {
		super(true);
	}

	@Override
	protected void generateContent() {
		grid.setWidget(0, 0, nameLabel);
		grid.setWidget(0, 1, nameBox);
		grid.setWidget(1, 0, addrLabel);
		grid.setWidget(1, 1, addrBox);
		grid.setWidget(2, 0, phoneLabel);
		grid.setWidget(2, 1, phoneBox);
		grid.setWidget(3, 1, button);
		add(grid);

		button.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				grid.setVisible(false);
				RootPanel.get().add(new Label("Thanks for your submission."));
				Window.alert("Submit name=" + nameBox.getText() + "\naddress=" + addrBox.getText() + "\nphone=" + phoneBox.getText());
			}
		});
	}

	@Override
	public String getHistoryActionToken() {
		return getHistoryTokenPrefix();
	}

	public static String getHistoryTokenPrefix() {
		return "Login";
	}

	public static String generateHistoryToken() {
		return AInteraction.generateHistoryToken(getHistoryTokenPrefix());
	}
}
